using UnityEngine;

public class UpgradeController : MonoBehaviour
{
	public GarageController GarageController;

	public int base_upgrade_price;

	public int price_factor;

	public float upgrade_speed;

	public float upgrade_acceleration;

	public float upgrade_brakes;

	public void SetDefaultValues(GameObject[] vehicles)
	{
		int num = 0;
		foreach (GameObject gameObject in vehicles)
		{
			PlayerPrefs.SetInt("vehicle_" + num + "_speed_price", base_upgrade_price);
			PlayerPrefs.SetInt("vehicle_" + num + "_acceleration_price", base_upgrade_price);
			PlayerPrefs.SetInt("vehicle_" + num + "_brakes_price", base_upgrade_price);
			num++;
		}
	}

	public void SetSpeed(int i)
	{
		if (GarageController.speed_slider.value + upgrade_speed < GarageController.speed_slider.maxValue)
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_speed", GarageController.speed_slider.value + upgrade_speed);
		}
		else
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_speed", GarageController.speed_slider.maxValue);
		}
	}

	public float GetSpeed(int i)
	{
		return PlayerPrefs.GetFloat("vehicle_" + i + "_speed", 0f);
	}

	public void SetAcceleration(int i)
	{
		if (GarageController.acceleration_slider.value + upgrade_acceleration < GarageController.acceleration_slider.maxValue)
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_acceleration", GarageController.acceleration_slider.value + upgrade_acceleration);
		}
		else
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_acceleration", GarageController.acceleration_slider.maxValue);
		}
	}

	public float GetAcceleration(int i)
	{
		return PlayerPrefs.GetFloat("vehicle_" + i + "_acceleration", 0f);
	}

	public void SetBrakes(int i)
	{
		if (GarageController.brakes_slider.value + upgrade_brakes < GarageController.brakes_slider.maxValue)
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_brakes", GarageController.brakes_slider.value + upgrade_brakes);
		}
		else
		{
			PlayerPrefs.SetFloat("vehicle_" + i + "_brakes", GarageController.brakes_slider.maxValue);
		}
	}

	public float GetBrakes(int i)
	{
		return PlayerPrefs.GetFloat("vehicle_" + i + "_brakes", 0f);
	}

	public void SetSpeedPrice(int i)
	{
		PlayerPrefs.SetInt("vehicle_" + i + "_speed_price", GetSpeedPrice(i) + price_factor);
	}

	public int GetSpeedPrice(int i)
	{
		return PlayerPrefs.GetInt("vehicle_" + i + "_speed_price", 0);
	}

	public void SetAccelerationPrice(int i)
	{
		PlayerPrefs.SetInt("vehicle_" + i + "_acceleration_price", GetAccelerationPrice(i) + price_factor);
	}

	public int GetAccelerationPrice(int i)
	{
		return PlayerPrefs.GetInt("vehicle_" + i + "_acceleration_price", 0);
	}

	public void SetBrakesPrice(int i)
	{
		PlayerPrefs.SetInt("vehicle_" + i + "_brakes_price", GetBrakesPrice(i) + price_factor);
	}

	public int GetBrakesPrice(int i)
	{
		return PlayerPrefs.GetInt("vehicle_" + i + "_brakes_price", 0);
	}

	public void UpgradeSpeed(int i)
	{
		SetSpeed(i);
		SetSpeedPrice(i);
	}

	public void UpgradeAcceleration(int i)
	{
		SetAcceleration(i);
		SetAccelerationPrice(i);
		PlayerPrefs.SetInt("vehicle_" + i + "_acceleration_upgraded", 1);
	}

	public void UpgradeBrakes(int i)
	{
		SetBrakes(i);
		SetBrakesPrice(i);
	}
}
